import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { readFileSync } from 'fs';
import { resolve } from 'path';

// 读取 package.json 获取版本信息
const packageJson = JSON.parse(readFileSync(resolve(process.cwd(), '../../package.json'), 'utf8'));

export default defineConfig({
  output: {
    assetPrefix: './',
  },
  plugins: [pluginReact()],
  server: {
    port: 3001,
  },
  html: {
    template: './public/index.html',
  },
  source: {
    define: {
      'process.env.REACT_APP_VERSION': JSON.stringify(packageJson.version),
    },
  },
});
